
/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package net.es.oscars.authN.http;

import org.apache.log4j.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import oasis.names.tc.saml._2_0.assertion.AttributeType;
import net.es.oscars.authN.soap.gen.*;
import net.es.oscars.authN.soap.gen.policy.*;
import net.es.oscars.authZ.soap.gen.*;
import net.es.oscars.common.soap.gen.*;
import net.es.oscars.logging.ErrSev;
import net.es.oscars.logging.ModuleName;
import net.es.oscars.logging.OSCARSNetLogger;

/**
 * This class was generated by Apache CXF 2.2.1
 * Fri May 15 16:39:44 PDT 2009
 * Generated source version: 2.2.1
 * 
 */

@javax.jws.WebService(
                      serviceName = "AuthNService",
                      portName = "AuthNPort",
                      targetNamespace = "http://oscars.es.net/OSCARS/AuthN",
                      endpointInterface = "net.es.oscars.authN.soap.gen.AuthNPortType")
@javax.xml.ws.BindingType(value = "http://www.w3.org/2003/05/soap/bindings/HTTP/")

public class AuthNSoapHandler implements net.es.oscars.authN.soap.gen.AuthNPortType {

    private static final Logger LOG = Logger.getLogger(AuthNSoapHandler.class.getName());

    /* (non-Javadoc)
     * @see net.es.oscars.authN.soap.gen.AuthNPortType#verifyLogin(net.es.oscars.authN.soap.gen.LoginId  verifyLoginReq )*
     */
    public net.es.oscars.authN.soap.gen.VerifyReply verifyLogin(VerifyLoginReqType verifyLoginReq) throws OSCARSFaultMessage    { 
        LOG.info("Executing operation verifyLogin");
        String loginName = verifyLoginReq.getLoginId().getLoginName();
        String password = verifyLoginReq.getLoginId().getPassword(); 
        VerifyReply reply = new VerifyReply();
        AttributeType at = new AttributeType();
        at.setName("role"); 
        at.getAttributeValue().add("OSCARS-engineer");
        try {
            // NOTE:  for testing
            if (loginName.equals(password)) {
                SubjectAttributes subAttr = new SubjectAttributes();
                subAttr.getSubjectAttribute().add(at);
                reply.setSubjectAttributes(subAttr);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        return reply;
        //throw new OSCARSFaultMessage("OSCARSFaultMessage...");
    }

    /* (non-Javadoc)
     * @see net.es.oscars.authN.soap.gen.AuthNPortType#verifyDN(net.es.oscars.authN.soap.gen.DNType  verifyDNReq )*
     */
    public VerifyReply verifyDN(VerifyDNReqType verifyDNReq) throws OSCARSFaultMessage    { 
        LOG.info("Executing operation verifyDN");
        System.out.println(verifyDNReq.getDN().getSubjectDN());
        VerifyReply reply = new VerifyReply();
        AttributeType at = new AttributeType();
        SubjectAttributes subAttr = new SubjectAttributes();
        at.setName("role"); 
        try {
            at.getAttributeValue().add("OSCARS-user");
            at.getAttributeValue().add("OSCARS-admin");
            subAttr.getSubjectAttribute().add(at);
            reply.setSubjectAttributes(subAttr);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        return reply;
        //throw new OSCARSFaultMessage("OSCARSFaultMessage...");
    }

    /**
     *  Can be used to authenticate the attributes passed in MessageProperties
     *  Not implemented yet
     */
    public VerifyReply verifyOriginator(VerifyOrigReqType verifyOriginatorReq ) 
            throws OSCARSFaultMessage {
        
        String event = "verifyOriginator";
        OSCARSNetLogger netLogger = OSCARSNetLogger.getTlogger();
        netLogger.init(ModuleName.AUTHN, verifyOriginatorReq.getTransactionId());
        LOG.debug(netLogger.start(event));
        LOG.error(netLogger.error(event,ErrSev.MINOR,"not implemented"));
        VerifyReply reply = new VerifyReply();
        reply.setTransactionId(verifyOriginatorReq.getTransactionId());
        reply.setSubjectAttributes(verifyOriginatorReq.getOriginator());
        return reply;
    }

}
